package mshop.com.schild_kotlin.fragments

import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import kotlinx.android.synthetic.main.fragment_hot.*
import mshop.com.schild_kotlin.R
import mshop.com.schild_kotlin.adapters.HotAdapter
import mshop.com.schild_kotlin.base.BaseFragment
import mshop.com.schild_kotlin.fragments.item_hot.RankFragment

/**
 * Created by mayi on 2018/5/23.
 * @Autor CaiWF
 * @Email 401885064@qq.com
 * @TODO
 */

class HotFragment : BaseFragment() {
    var tabTitles = listOf<String>("周榜", "月榜", "总榜")
    val STRATEGY = arrayOf("weekly", "monthly", "historical")
    var fragmentArr = ArrayList<Fragment>()
    var hotAdapter: HotAdapter? = null

    companion object {
        fun getInstall(): HotFragment {
            val home_fragment = HotFragment()
            val bundle = Bundle()
            home_fragment.arguments = bundle
            return home_fragment
        }
    }


    override fun initView() {
        initFragments()
        hotAdapter = fragmentManager?.let { HotAdapter(it, tabTitles, fragmentArr) }
        view_pager.adapter = hotAdapter

//        for (item in tabTitles) {//手动添加
//            val tab = tab_layout.newTab()
//            tab.text = item
//            tab_layout.addTab(tab)
//        }
        tab_layout.tabMode = TabLayout.MODE_FIXED///设置标签模式,有Fixed固定模式和Scrollable可以滑动模式两种
        tab_layout.setupWithViewPager(view_pager)
    }

    override fun getLayoutResources(): Int {
        return R.layout.fragment_hot
    }

    override fun getNeedRefresh(): Boolean {
        return false
    }

    override fun onRefresh() {

    }

    fun initFragments() {
        fragmentArr.add(RankFragment.getInstall(STRATEGY[0]))
        fragmentArr.add(RankFragment.getInstall(STRATEGY[1]))
        fragmentArr.add(RankFragment.getInstall(STRATEGY[2]))
    }


    /*
tabLayout.setOnTabSelectedListener ():给tablayout添加监听
tabLayout.setSelectedTabIndicatorHeight (100):设置选中标签指示器的高度
tabLayout.setSelectedTabIndicatorColor ():设置选中标签指示器的颜色
tabLayout.setTabGravity ():设置标签的位置
app:tabIndicatorColor:设置指示器颜色
app:tabSelectedTextColor设置当前选中的标签文字颜色
app:tabTextColor 设置标签文字颜色
     */

}